package droid;

import robocode.ScannedRobotEvent;
import robocode.TeamRobot;

public class AbstractBoot extends TeamRobot {

	public int posRoboAdvX = 0;
	public int posRoboAdvY = 0;
	public double velRoboAdv = 0;
	public double angRobAdv = 45;
	public double enemyX = 0.0;
	public double enemyY = 0.0;
	public double distRoboAdv = 0;
	boolean direita = false;

	public void setaDadosRoboADV(ScannedRobotEvent e) {

		angRobAdv = e.getBearing();
		distRoboAdv = e.getDistance();
		velRoboAdv = e.getVelocity();
		
		double enemyBearing = this.getHeading() + e.getBearing();
		// Calculate enemy's position
		enemyX = getX() + e.getDistance() * Math.sin(Math.toRadians(enemyBearing));
		enemyY = getY() + e.getDistance() * Math.cos(Math.toRadians(enemyBearing)); 
	}

	public void descrobreDirecao() {

		if (direita) {

			direita = false;
			setTurnRight(angRobAdv);

		} else {

			direita = true;
			setTurnLeft(angRobAdv);
		}
	}

	public double anguloRelativo(double ANG) {
		if (ANG > -180 && ANG <= 180)
			return ANG;
		double REL = ANG;
		while (REL <= -180)
			REL += 360;
		while (ANG > 180)
			REL -= 360;
		return REL;
	}

	public void mira(double Adv) {
		double A = getHeading() + Adv - getGunHeading();
		if (!(A > -180 && A <= 180)) {
			while (A <= -180)
				A += 360;
			while (A > 180)
				A -= 360;
		}
		turnGunRight(A);
	}

	public void dancinha() {
		setAhead(5);
		setTurnRight(360D);
		setTurnGunLeft(360D);
		setTurnRadarRight(30D);
	}

	public boolean pertoParede() {

		return (getX() < 50 || getX() > getBattleFieldWidth() - 50
				|| getY() < 50 || getY() > getBattleFieldHeight() - 50);
	}

	public void fogo(double Distancia) {

		if (Distancia > 200 || getEnergy() < 15)
			fire(1);
		else if (Distancia > 80)
			setFireBullet(2.5);
		else
			setFireBullet(3);
	}

	public void tiroFatal(double EnergiaIni) {
		double Tiro = (EnergiaIni / 4) + .1;
		fire(Tiro);
	}
}
